﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using RAP.Framework.Libary.Utils;

namespace RAP.Framework.Libary.DataSource.Model
{
  /// <summary>
  /// 数据库查询结果字段基本信息
  /// </summary>
  public class DBField
  {
    protected string _name = string.Empty;


    /// <summary>
    /// 
    /// </summary>
    public string Name
    {
      get
      {
        return _name;
      }
      set
      {
        if (value.IsNullOrEmpty())
        {
          throw new NullReferenceException("DBField.Name属性不能为null或空字符串！");
        }
        if (value.EndsWith(')'))
        {
          //如果字段名称中包含了“(...)”，则提取实体模型名称
          _name = value.LeftSubstring('(');
          this.ModelName = value.MidSubstring('(', ')');
        }
        else
        {
          _name = value;
        }

      }
    }

    /// <summary>
    /// 
    /// </summary>
    public string Type { get; set; }

    /// <summary>
    /// 
    /// </summary>
    public int Index { get; set; }

    /// <summary>
    /// 实体模型名称，从数据库查询数据返回时会自动将该字段转换成指定实体模型名称的类型
    /// </summary>
    public string ModelName { get; protected set; }
  }
}
